// wx-getSetting 方法的 Promise 封装
export const getSetting = () => {
  return new Promise((resolve, reject) => {
    wx.getSetting({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}

// wx-chooseAddress 方法的 Promise 封装
export const chooseAddress = () => {
  return new Promise((resolve, reject) => {
    wx.chooseAddress({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}

// wx-openSetting 方法的 Promise 封装
export const openSetting = () => {
  return new Promise((resolve, reject) => {
    wx.openSetting({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}


/**
 * wx.showModal 方法的 Promise 封装
 * @param {Object} param0  参数
 */
export const showModal = ({ content }) => {
  return new Promise((resolve, reject) => {
    wx.showModal({
      title: '提示',
      content: content,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

/**
 * wx.showToast 方法的 Promise 封装
 * @param {Object} param0  参数
 */
export const showToast = ({ title }) => {
  return new Promise((resolve, reject) => {
    wx.showToast({
      title: title,
      icon: 'none',
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}


/**
 * wx.login 方法的 Promise 封装
 */
 export const login = () => {
  return new Promise((resolve, reject) => {
    wx.login({
      timeout:10000,
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      }
    });
      
  })
}


/**
 * 微信小程序的支付功能
 * wx.requestPayment 方法的 Promise 封装
 * @param {object} pay 支付所必要的参数
 */
 export const requestPayment = (pay) => {
  return new Promise((resolve, reject) => {
    wx.requestPayment({
      ...pay,
      // nonceStr: 'nonceStr',
      // package: 'package',
      // paySign: 'paySign',
      // timeStamp: 'timeStamp',
      // signType: signType,
      success: (res) => {
        console.log('成功');
        resolve(res)
      },
      fail: (err) => {
        console.log('失败');
        reject(err)
      },
      // complete: (res) => {},
    })
      
  })
}